package com.ruoyi.dto;

import lombok.Data;

@Data
public class DataWrapper<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public static <A> DataWrapper<A> of(boolean success, int code, String message, A data) {
        DataWrapper<A> responseDataWrapper = new DataWrapper<>();
        responseDataWrapper.setSuccess(success);
        responseDataWrapper.setCode(code);
        responseDataWrapper.setMessage(message);
        responseDataWrapper.setData(data);
        return responseDataWrapper;
    }

    public static <A> DataWrapper<A> success(A data){
        return of(true, 0, "", data);
    }

    public static DataWrapper<String> success(){
        return of(true, 0, "", null);
    }

    public static <A> DataWrapper<Object> fail(int code, String message){
        return of(false, code, message, null);
    }

    public static <A> DataWrapper<Object> fail(String message){
        return of(false, -2, message, null);
    }
}
